package it.uniroma2.art.owlart.model.syntax.manchester;

import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.model.NodeFilters;


public class Uri {
	private boolean inverseProp;
	private String name;
	public String prefix;
	public OWLModel model;
	public ARTURIResource uriRes;
	private String nameSpace;

	public Uri(String u,OWLModel mod) {
		inverseProp=false;
		name=u;
		model=mod;
		nameSpace=mod.getDefaultNamespace();

		try {
		    int prefixIndex=name.indexOf(":");
	    	    if(prefixIndex != -1) {
	    		int length=name.length();
	    		prefix=name.substring(0, prefixIndex);
	    		name=name.substring(prefixIndex+1,length);

	    		nameSpace = mod.getNSForPrefix(prefix);
	    		if(nameSpace==null) throw new NullPointerException("prefix "+prefix+" (on local name"+name+")");
		    }
	    	

		    uriRes = model.retrieveURIResource(nameSpace+name, NodeFilters.MAINGRAPH);
		    if(uriRes==null) throw new NullPointerException(nameSpace+name);
		} catch (ModelAccessException e) {
		    e.getMessage();
		}

	}

	public void setInverseProp() {
		inverseProp=true;
	}

	public boolean isInverseProp() {
		return inverseProp;
	}

	public String getLocalName() {
		return name;
	}
	public String getNameSpace() {
		return nameSpace;
	}

}
